# -*- coding: utf-8 -*-
import numpy as np

'''
打印7阶魔方
'''
a = np.array([672,670,771,308,476,413,221,
              685,619,204,990,802,789,497,
              411,696,445,612,390,963,351,
              926,604,528,280,844,328,710,
              459,815,327,842,875,447,924,
              396,294,254,748,690,305,261,
              208,965,816,348,169,976,118]).reshape(7,7);
b = np.array([221, 494, 780, 354, 989, 569, 915,
              497, 665, 896, 291, 570, 764, 730,
              351, 833, 362, 575, 214, 510, 432,
              710, 400, 916, 564, 298, 130, 830,
              924, 486, 801, 584, 994, 870, 536,
              261, 948, 349, 250, 946, 582, 545,
              118, 133, 856, 442, 392, 215, 304]).reshape(7,7);
c= np.array([915, 750, 201, 440, 846, 954, 952,
            730, 483, 908, 609, 981, 752, 642,
            432, 453, 380, 256, 245, 168, 860,
            830, 828, 205, 857, 729, 904, 387,
            536, 430, 369, 774, 533, 456, 806,
            545, 689, 375, 949, 192, 804, 335,
            304, 176, 402, 290, 632, 183, 450]).reshape(7,7);
d= np.array([952, 100, 112, 346, 618, 925, 672,
            642, 843, 633, 598, 507, 705, 685,
            860, 356, 532, 827, 147, 687, 411,
            387, 978, 576, 772, 515, 423, 926,
            806, 725, 649, 831, 667, 537, 459,
            335, 727, 310, 920, 798, 309,396,
            450, 246, 996, 834, 889, 172, 208]).reshape(7,7);
e= np.array([952, 954, 846, 440, 201, 750, 915,
            100, 544, 822, 512, 253, 345, 569,
            112, 546, 426, 207, 980, 820, 989,
            346, 255, 531, 463, 284, 516, 354,
            618, 529, 141, 608, 361, 493, 780,
            925, 955, 744, 198, 945, 876, 494,
            672, 670, 771, 308, 476, 413, 221]).reshape(7,7);
f = np.array([208, 965, 816, 348, 169, 976, 118,
            172, 105, 195, 910, 548, 156, 133,
            889, 554, 418, 573, 610, 170, 856,
            834, 700, 930, 671, 697, 517, 442,
            996, 125, 166, 674, 222, 974, 392,
            246, 429, 986, 123, 382, 975, 215,
            450, 183, 632, 290, 402, 176, 304]).reshape(7,7);

print( u"数组a:\r\n",a );
print( u"数组b:\r\n",b );
print( u"数组c:\r\n",c );
print( u"数组d:\r\n",d );
print( u"数组e:\r\n",e );
print( u"数组f:\r\n",f );


'''
寻找素数(质数)
'''
def findPrime( array ):
    ret2array = [];

    for l in range( 7 ):
        for h in np.arange( 7 ):

           # 检查质数
           isPrime = True
           for num2check in range( 2, array[ l,h ] - 1 ):
               if( ( array[l, h] % num2check ) == 0 ):
                   isPrime = False;

           if( isPrime ):
               ret2array.append( array[ l,h ] );

    return ret2array;

print( 'A:', findPrime( a ), "\r\n" )
print( 'B:', findPrime( b ), "\r\n" )
print( 'C:', findPrime( c ), "\r\n" )
print( 'D:', findPrime( d ), "\r\n" )
print( 'E:', findPrime( e ), "\r\n" )
print( 'F:', findPrime( f ), "\r\n" )

'''
    一次循环找出素数
'''
def isPrime( num ):
    isPrime = True
    for num2check in range(2, num - 1):
        if ( ( num % num2check ) == 0 ):
            isPrime = False;
    return isPrime;

# print( a.reshape(1,49) )
# print( a.ravel() )

def findPrime_V2( array ):
    ret2array = [];
    for num2check in array.ravel():
        if( isPrime( num2check ) ):
            ret2array.append( num2check );

    return ret2array;


print( 'A:', findPrime_V2( a ), "\r\n" )
print( 'B:', findPrime_V2( b ), "\r\n" )
print( 'C:', findPrime_V2( c ), "\r\n" )
print( 'D:', findPrime_V2( d ), "\r\n" )
print( 'E:', findPrime_V2( e ), "\r\n" )
print( 'F:', findPrime_V2( f ), "\r\n" )


